package ofpof.domain.dao.mapper;

import java.util.Date;

import ofpof.domain.RemembermeToken;

import org.bson.types.ObjectId;
import org.springframework.stereotype.Component;

import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;

@Component
public class RemembermeTokenMapper implements MongoMapper<RemembermeToken> {

	@Override
	public RemembermeToken fromDbObject(DBObject dbObject) {
		RemembermeToken remembermeToken = new RemembermeToken();
		remembermeToken.setLastLogin((Date) dbObject.get("lastlogin"));
		remembermeToken.setId((ObjectId) dbObject.get("_id"));
		remembermeToken.setEmail((String) dbObject.get("email"));
		remembermeToken.setToken((String) dbObject.get("token"));
		return remembermeToken;
	}

	@Override
	public DBObject toDbObject(RemembermeToken entity) {
		DBObject dbObject  = new BasicDBObject();
		dbObject.put("_id",  entity.getId());
		dbObject.put("lastlogin",entity.getLastLogin());
		dbObject.put("email", entity.getEmail());
		dbObject.put("token", entity.getToken());
		return dbObject;
	}

}
